home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
034a
/
twview82.zip
/
PATHSTUF.INC
< prev
next >
Wrap
Text File
|
1991-02-04
|
6KB
|
187 lines
procedure PrintPath( var home : sector; sec : sector );
begin
if home = sec then
write( sec )
else
begin
PrintPath( home, distances[ sec ].s );
write( ' - ', sec );
end; {induction}
end;
function FixPath( start, finish : sector ) : integer;
{ Adjusts Distances from start up to point were finish is entered;
returns length of path. }
var
s : sector;
breadth : queue;
daddy, sonny : sector;
i : warpindex;
done : boolean;
begin
for s := 1 to maxSector do
Distances[s].d := -1;
breadth.front := 0;
enqueue( breadth, start, start );
repeat
serve( breadth, daddy, sonny );
if Distances[ sonny ].d = -1 then {haven't hit him before:}
begin
distances[ sonny ].d := distances[ daddy ].d + 1;
distances[ sonny ].s := daddy;
with space.sectors[ sonny ] do if number > 0 then
for i := 1 to number do
enqueue( breadth, sonny, data[ i ] );
done := sonny = finish;
end; {if}
until done or (breadth.front = 0);
FixPath := distances[ finish ].d;
for s := 1 to maxSector do
if distances[s].d = -1 then distances[s].d := maxint;
end; {FixPath}
procedure PathLength;
var
s1, s2 : sector;
begin
write('Distance between which two sectors? ');
readln( s1, s2 );
if space.sectors[ s1 ].number <> Unexplored then
begin
if FixPath( s1, s2) = Error then
writeln('You don''t know how to get to ', s2, ' from ', s1, '!' )
else
begin
writeln('Known shortest path from ', s1, ' to ', s2, ' is ');
PrintPath( s1, s2 );
writeln;
end; {if finite distance}
end {visited}
else
writeln('Never visited ', s1, ' so can''t tell distances leaving it.');
if space.sectors[ s1 ].number <> UnExplored then
begin
if FixPath( s2, s1 ) = Error then
writeln('You don''t know how to get to ', s1, ' from ', s2, '!' )
else
begin
writeln('Known shortest path from ', s2, ' to ', s1, ' is ');
PrintPath( s2, s1 );
writeln;
end; {if finite distance}
end
else
writeln('Never visited ', s2, ' so can''t tell distances leaving it.');
end;
procedure NearestFighters;
var
s, s1, Closest : sector;
begin
write('What is your current sector? ');
readln( s );
FixDistances( s, distances );
Closest := 1;
for s1 := 1 to maxSector do
if space.sectors[ s1 ].portType = Class0 then
if distances[ s1 ].d = maxint then
writeln('You don''t know how to get to ', s1 )
else
begin
writeln('Path to ', s1, ' is of length ', distances[ s1 ].d );
PrintPath( s, s1 );
writeln;
if distances[ s1 ].d < distances[ Closest ].d then
Closest := s1;
end; {for if else}
end; {Nearest Fighters}
procedure MajorSpaceLanes;
{ The major space lanes consist of the triangle of paths between SpaceDock and
the two class 0 ports (excluding Terra), together with the path between SpaceDock
and Terra. }
const
MaxClass0s = 3; { If more than 3, code may need to be changed. }
var
MajorTradeRoute : array [ sector ] of boolean;
s : sector;
Class0s : array [1..MaxClass0s] of sector;
i,
Known0s : 0..MaxClass0s;
f : text;
count : integer;
EchoDisk : Boolean;
procedure TogglePath( home, sec : SectorIndex);
begin
MajorTradeRoute[ sec ] := true;
if sec <> home then
TogglePath( home, distances[ sec ].s );
end; {TogglePath}
begin
if space.dock = 0 then
writeln('You don''t know where the space dock is? I''m not going to try...')
else
begin
for s := 1 to MaxSector do
MajorTradeRoute[ s ] := false;
Known0s := 0;
for s := 1 to MaxSector do
if space.sectors[s].portType = Class0 then
begin
Known0s := Known0s + 1;
Class0s[ Known0s ] := s;
end; {for if}
if Known0s <> MaxClass0s then
writeln('Warning: not all Class 0 ports have been discovered!');
if Known0s = 0 then
begin writeln('Incomplete data. Aborting...'); exit; end;
write('Class 0 ports: ');
for i := 1 to Known0s do
write( Class0s[ i ] : 5 );
writeln;
for i := 1 to Known0s do
begin
if FixPath( space.dock, Class0s[ i ] ) = Error then
writeln('You don''t know how to get from the dock to ', Class0s[i], '!')
else
TogglePath( space.dock, Class0s[ i ] );
if FixPath( Class0s[ i ], space.dock ) = Error then
writeln('You don''t know how to get to the dock from ', Class0s[i], '!')
else
TogglePath( Class0s[i], space.dock);
end; {for}
if Known0s = 3 then
begin
if FixPath( Class0s[2], Class0s[3] ) <> Error then
TogglePath( Class0s[2], Class0s[3] )
else
writeln('You don''t know how to get from ', Class0s[2], ' to ',
Class0s[3] );
if FixPath( Class0s[3], Class0s[3] ) <> Error then
TogglePath( Class0s[3], Class0s[3] )
else
writeln('You don''t know how to get from ', Class0s[3], ' to ',
Class0s[2] );
end; {if}
EchoDisk := LogToDisk( f, 'Do you want the results echoed to disk? ');
for s := 1 to maxSector do
if MajorTradeRoute[ s ] then write( s : 5 );
if EchoDisk then
begin
writeln(f, 'estimated Major Space Lanes');
count := 0;
for s := 1 to maxSector do
if MajorTradeRoute[ s ] then
begin
count := count + 1;
write( f, s:5 );
if count mod 10 = 0 then writeln( f );
end; {for if}
close( f );
end; {if}
end; {else}
writeln;
end; {SpaceLanes}